package org.example.userservice.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.example.userservice.entity.OperationLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class LogProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public void sendLog(Long userId, String action, String ip, String detail) {
        OperationLog operationLog = new OperationLog();
        operationLog.setUserId(userId);
        operationLog.setAction(action);
        operationLog.setIp(ip);
        operationLog.setDetail(detail);
        log.info("发送操作日志：{}", operationLog);
        rocketMQTemplate.convertAndSend("operation-log-topic", operationLog);
    }
}